﻿using NUnit.Framework;
using SmartPeople.Framework.SecuritySpace;
using SmartPeople.Framework.SecuritySpace.Tests;

namespace SmartPeople.Framework.SecuritySpace.Tests
{
    [TestFixture]
    public class SecuritySpaceTests
    {
        private void Init(ISecuritySpace securitySpace)
        {
            securitySpace.Clear();

            ISecuritySecuredType securedFolder = securitySpace.SecuredTypes.CreateType("folder");
            securedFolder.Actions.CreateAction(TestActions.List);
            securedFolder.Actions.CreateAction(TestActions.Read);
            securedFolder.Actions.CreateAction(TestActions.Create);
            securedFolder.Actions.CreateAction(TestActions.Modify);
            securedFolder.Actions.CreateAction(TestActions.Delete);

            ISecuritySecuredType securedFile = securitySpace.SecuredTypes.CreateType("unknownFileType");
            securedFile.Actions.CreateAction(TestActions.Read);
            securedFile.Actions.CreateAction(TestActions.Create);
            securedFile.Actions.CreateAction(TestActions.Modify);
            securedFile.Actions.CreateAction(TestActions.Delete);

            securedFile.States.CreateState(TestStates.New);
            securedFile.States.CreateState(TestStates.Normal);
            securedFile.States.CreateState(TestStates.Protected);

            ISecuritySecuredType baseSecuredProperty = securitySpace.SecuredTypes.CreateType("BaseProperty");
            baseSecuredProperty.Actions.CreateAction(TestActions.Get);
            baseSecuredProperty.Actions.CreateAction(TestActions.Set);


            securitySpace.SecuredDocuments.SetDefaultPathType(securedFolder);
            securitySpace.SecuredDocuments.SetDefaultDocumentType(securedFile);

            securitySpace.Roles.CreateRole(TestRoles.Administrators);
            securitySpace.Roles.CreateRole(TestRoles.Operators);
            securitySpace.Roles.CreateRole(TestRoles.Users);

            securitySpace.Users.CreateUser(TestUsers.System, TestUsers.User1Password, "system@acme.com",
                                           "What is you fathers middle name?", "Douglas", true, "System User Comment");
            securitySpace.Users.CreateUser(TestUsers.Administrator, "admin", "administrator@acme.com",
                                           "What is you fathers middle name?", "Douglas", true, "System User Comment");
            securitySpace.Users.CreateUser(TestUsers.Guest, "guest", "guest@acme.com",
                                           "What is you fathers middle name?", "Douglas", true, "System User Comment");
            securitySpace.Users.CreateUser(TestUsers.User1, "user1", "user1@acme.com",
                                           "What is you fathers middle name?", "Douglas", true, "System User Comment");
        }
    }
}